
#import "N1NoneView.h"
@interface N1NoneView ()

@property (nonatomic,strong)UIImageView *m1_noImg;

@property (nonatomic,strong)UILabel *m1_TitleL;

@property (nonatomic,strong)UIButton *m1_desBtn;

@property (nonatomic,strong)UIButton *m1_noneBtn;

@end


@implementation N1NoneView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = m1_bg_color;
        self.userInteractionEnabled = YES;
        [self addSubview:self.m1_noImg];
        [self addSubview:self.m1_TitleL];
        [self addSubview:self.m1_desBtn];
        [self addSubview:self.m1_noneBtn];
    }
    return self;
}

-(UIImageView *)m1_noImg{
    if (!_m1_noImg) {
        _m1_noImg = [[UIImageView alloc] init];
        _m1_noImg.frame = CGRectMake(60, 60, SCREENWIDTH - 120, 10);
        _m1_noImg.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _m1_noImg;
}

-(UILabel *)m1_TitleL{
    if (!_m1_TitleL) {
        _m1_TitleL = [[UILabel alloc] initWithFrame:CGRectMake(0, _m1_noImg.frame.size.height + _m1_noImg.frame.origin.y + 5, SCREENWIDTH, 20)];
        _m1_TitleL.font = m1_font(16);
        _m1_TitleL.textAlignment = NSTextAlignmentCenter;
        _m1_TitleL.textColor = [UIColor m1_colorHex:0x666666];
    }
    return _m1_TitleL;
}

-(UIButton *)m1_desBtn{
    if (!_m1_desBtn) {
        _m1_desBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _m1_desBtn.frame = CGRectMake(0, _m1_TitleL.frame.size.height + _m1_TitleL.frame.origin.y +5, SCREENWIDTH, 20);
        [_m1_desBtn setTintColor:[UIColor m1_colorHex:0x666666]];
        _m1_desBtn.titleLabel.font = m1_font(12);
    }
    return _m1_desBtn;
}

-(UIButton *)m1_noneBtn{
    if (!_m1_noneBtn) {
        _m1_noneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _m1_noneBtn.frame = CGRectMake(40, _m1_desBtn.frame.origin.y + _m1_desBtn.frame.size.height + 20, SCREENWIDTH - 80, 44);
        [_m1_noneBtn setBackgroundColor:[UIColor m1_colorHex:0xE54545]];
        _m1_noneBtn.layer.cornerRadius = 22;
        _m1_noneBtn.layer.masksToBounds = YES;
        _m1_noneBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [_m1_noneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _m1_noneBtn.enabled = YES;
    }
    return _m1_noneBtn;
}


- (void)m1_setImage:(NSString *)imageName withSize:(CGSize)img_size img_y:(CGFloat)imag_y{
    _m1_noImg.image = [UIImage imageNamed:imageName];
    _m1_noImg.frame = CGRectMake((SCREENWIDTH - img_size.width)/2, imag_y, img_size.width,img_size.height);
    _m1_TitleL.frame = CGRectMake(0, _m1_noImg.frame.size.height + _m1_noImg.frame.origin.y + 20, SCREENWIDTH, 20);
    _m1_desBtn.frame = CGRectMake(0, _m1_TitleL.frame.size.height + _m1_TitleL.frame.origin.y +5, SCREENWIDTH, 20);

        _m1_noneBtn.frame = CGRectMake(40, _m1_desBtn.frame.origin.y + _m1_desBtn.frame.size.height + 50, SCREENWIDTH - 80, 44);

}

-(void)m1_setTitle:(NSString *)noneTitle noneDec:(NSString *)noneDec noneBtnTitle:(NSString *)btnTitle{
    _m1_TitleL.text = noneTitle;
    [_m1_desBtn setTitle:noneDec forState:UIControlStateNormal];
    _m1_noneBtn.titleLabel.text = btnTitle;
    [_m1_noneBtn setTitle:btnTitle forState:UIControlStateNormal];

        self.m1_noneBtn.hidden = [self isEmpty:btnTitle];
    self.m1_TitleL.hidden = [self isEmpty:noneTitle];
    self.m1_desBtn.hidden = [self isEmpty:noneDec];
}

- (void)setReloadClickBlock:(void (^)(void))reloadClickBlock{
    
    _reloadClickBlock = reloadClickBlock;
    [self.m1_noneBtn removeTarget:nil action:nil forControlEvents:UIControlEventAllEvents];
    [self.m1_noneBtn addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonAction{

    if(self.reloadClickBlock){
        _reloadClickBlock();
    }
}

- (BOOL)isEmpty:(NSString *)string
{
    if (![string isKindOfClass:[NSString class]])
        string = [string description];
    if (string == nil || string == NULL)
        return YES;
    if ([string isKindOfClass:[NSNull class]])
        return YES;
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0)
        return YES;
    if ([string isEqualToString:@"(null)"])
        return YES;
    if ([string isEqualToString:@"(null)(null)"])
        return YES;
    if ([string isEqualToString:@"<null>"])
        return YES;
    
    // return Default
    return NO;
}

@end
